<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns="http://www.w3.org/1999/xhtml">
    
    <h:form id="form1">
            
    
            <p:dataTable id="tabIcms" var="val" value="#{icmsFace.listaI}" 
                         selectionMode="single" emptyMessage="Nenhum registro encontrado."
                         height="50">

                <f:facet name="header" >ICMS
                </f:facet>

                <p:column sortBy="#{val.id}">
                    <f:facet name="header"><h:outputText value="Id"/></f:facet>
                    <h:outputText value="#{val.id}"/>
                </p:column>

                <p:column  sortBy="#{val.conce.abrev}">
                    <f:facet name="header">Concessionária</f:facet>
                    <h:outputText value="#{val.conce.abrev}"/>
                </p:column>

                <p:column  sortBy="#{val.valor}">
                    <f:facet name="header">Valor</f:facet>
                    <h:outputText value="#{val.valor}" >
                        <f:convertNumber type="percent"/>
                    </h:outputText>
                </p:column>

                <p:column  sortBy="#{val.tipoUso.descricao}">
                    <f:facet name="header">Tipo de Uso</f:facet>
                    <h:outputText value="#{val.tipoUso.descricao}" >                        
                    </h:outputText>
                </p:column>

                <p:column>
                    <f:facet name="header">Ações</f:facet>
                    <p:commandButton image="ui-icon-pencil" update=":form1:painel2" 
                                     oncomplete="icmsDialog.show()" title="Editar" >
                        <f:setPropertyActionListener value="#{val}" target="#{icmsFace.selectedIcm}" />
                    </p:commandButton>

                    <p:commandButton image="ui-icon-trash" update=":form1:painel2"
                                     title="Excluir" oncomplete="confirmIcms.show()" >
                        <f:setPropertyActionListener value="#{val}" target="#{icmsFace.selectedIcm}" />
                    </p:commandButton>
                    
                </p:column>
                <f:facet name="footer" >
                    <p:commandButton image="ui-icon-disk" update=":form1:painel2"
                                     title="Novo" value="Novo" oncomplete="icmsDialog.show()"
                                     action="#{icmsFace.doCreate}"/>
                </f:facet>
            </p:dataTable>

            <p:dialog widgetVar="icmsDialog" width="600" resizable="true"
                      id="icmsDlg" header="Cadastro de ICMS" showEffect="explode"
                      hideEffect="slide">
                <p:outputPanel id="painel2" rendered="true" >
                    <script type="text/javascript">
                        (function($){
                            $(function(){
                                $('input:text').setMask();
                            });
                        })(jQuery);
                    </script>
                    <h:panelGrid columns="2"  >
                        <h:outputLabel value="Concessionária:" />
                        <h:selectOneMenu  value="#{icmsFace.selectedIcm.conce}" converter="conceConverter" 
                                          rendered="true" >
                            <f:selectItems   value="#{icmsFace.listaConce}" var="cbConce"
                                             itemLabel="#{cbConce.abrev}" itemValue="#{cbConce}" />
                            
                        </h:selectOneMenu>
                        <h:outputLabel value="Tipo de Uso" />
                        <h:selectOneMenu  value="#{icmsFace.selectedIcm.tipoUso}" converter="tipoUsoConverter" 
                                          rendered="true" >
                            <f:selectItems   value="#{icmsFace.listaT}" var="cbTipoUso"
                                             itemLabel="#{cbTipoUso.descricao}" itemValue="#{cbTipoUso}" />
                            
                        </h:selectOneMenu>

                        
                        <h:outputLabel value="Valor Icms:"/>
                        <p:inputText id="idesc2i" value="#{icmsFace.selectedIcm.valor}"
                                     rendered="true" alt="decimal" >
                            <f:convertNumber locale="pt_BR" minFractionDigits="2"/>
                        </p:inputText>

                        <h:outputLabel value="Início:"/>
                        <p:calendar value="#{icmsFace.selectedIcm.inicio}" rendered="true">
                            <f:convertDateTime locale="pt_BR"/>
                        </p:calendar>
                        
                        <p:commandButton value="Salvar" action="#{icmsFace.doSave}"
                                         oncomplete="icmsDialog.hide()" update="tabIcms">

                        </p:commandButton>
                        <p:commandButton value="Cancelar" oncomplete="icmsDialog.hide()" action="#{icmsFace.resetIsNew}"/>
                    </h:panelGrid>

                </p:outputPanel>
            </p:dialog>

            <p:confirmDialog message="Você deseja realmente exluir este registro?" width="200"
                             showEffect="explode" hideEffect="explode"
                             header="Confirmação" severity="alert" widgetVar="confirmIcms" modal="true" >

                <p:commandButton value="Sim" update="tabIcms" action="#{icmsFace.doRemove()}"
                                 oncomplete="confirmIcms.hide()"/>
                <p:commandButton value="Não" onclick="confirmIcms.hide()" type="button" />

            </p:confirmDialog>
            <br></br>
</h:form>
</ui:composition>